<?php

namespace app\api\controller;

use app\hander\HelpHander;
use app\repositories\UserRepository;
use think\Request;

class User extends Base
{
	
	protected function initialize()
	{
		parent::initialize();
	}
	
	/**
	 * 个人中心
	 * @Function center
	 * @param Request $request
	 *
	 * @Author   tegic
	 * @Time     2018/6/4 20:28
	 */
	public function center(Request $request)
	{
		$data = UserRepository::find($request->userId);
		var_dump($data);
	}
	
	/**
	 * 登录
	 * @Function login
	 *
	 * @param Request $request
	 *
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 * @Author   tegic
	 * @Time     2018/6/4 15:51
	 */
	public function login(Request $request)
	{
		$data = UserRepository::login($request->param());
		if (!$data) {
			HelpHander::Response('用户名或密码错误', 400, $data);
		}
		HelpHander::Response('登录成功', 200, $data);
	}
	
	/**
	 * 注册
	 * @Function register
	 *
	 * @param Request $request
	 *
	 * @Author   tegic
	 * @Time     2018/6/4 15:33
	 */
	public function register(Request $request)
	{
		$data = UserRepository::register($request->param());
		if (!is_array($data)) {
			HelpHander::Response($data, 400);
		}
		HelpHander::Response('注册成功', 200, $data);
	}
	
	public function test()
	{
		$data = UserRepository::test();
		
	}
	
}
